<template>
  <div style="margin: 0 auto; width: 840px;">
    <el-row style="margin: 0 auto 20px; width: 600px; font-size: medium; text-align: center; line-height: 2.0; color: #3789dc">
      <b>
        浙工大审通（{{ form.noticeYear }}）{{ form.noticeCode }}号
      </b>
    </el-row>
    <el-row style="margin: 10px auto 20px; width: 840px; font-size: small; text-align: center; line-height: 2.0;">
      <hr/>
      创建单位：{{ form.auditCompanyName }} &nbsp; 创建时间：{{ form.releaseTime }}
    </el-row>
    <el-row style="margin: 0 auto 20px; width: 600px; font-size: medium; text-align: center; line-height: 2.0;">
      <b>
        关于对{{ form.auditedUserInfo }}进行{{ form.auditTypeSub}}<br/>经济责任审计的通知
      </b>
    </el-row>
    <el-row>
      <el-col :span="10">
        <el-form-item label-width="0" prop="auditedCompanyName" :rules="{required: true, message: '被审计单位不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.auditedCompanyName" @focus="showTransferDialog(['auditedCompanyId','auditedCompanyName'], 'company', false, 2)" :readonly="true">
            <span slot="append">:</span>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col style="width: 338px">
        <el-form-item label-width="28px">
          <el-col>
            我处受党委组织部的委托，决定派出审计小组，自
          </el-col>
        </el-form-item>
      </el-col>
      <el-col style="width: 143px;">
        <el-form-item label-width="0" prop="projectDate">
          <el-date-picker placement="bottom-start" v-model="form.projectDate" :disabled="formDisplay" type="date" placeholder="选择日期" ></el-date-picker>
        </el-form-item>
      </el-col>
      <el-col style="width: 128px">
        <el-form-item label-width="0">
          起，对你单位原院长
        </el-form-item>
      </el-col>
      <el-col style="width: 190px; text-align: center">
        <el-form-item label-width="0">
          {{ form.auditedUserNames }}
        </el-form-item>
      </el-col>
      <el-col style="width: 28px">
        <el-form-item label-width="0">
          同志
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col style="width: 56px">
        <el-form-item label-width="0">
          {{ form.auditTypeSub }}期间
        </el-form-item>
      </el-col>
      <el-col style="width: 225px;">
        <el-form-item label-width="0" prop="tenureDates">
          <el-date-picker placement="bottom-start" v-model="form.tenureDates" :disabled="formDisplay" type="daterange" unlink-panels range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
      </el-col>
      <el-col style="width: 548px">
        <el-form-item label-width="0">
          的经济责任情况进行审计（重点审计最近两年，必要时可追溯到以前年度）。请予积极配
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col style="width: 590px">
        <el-form-item label-width="0">
          合，并提供有关资料（见附件1）和领导干部经济责任审计述职报告（主要内容要求见附件2）。
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col style="width: 827px; display: flex; justify-content: flex-end;">
        审计处
      </el-col>
    </el-row>
    <el-row>
      <el-col style="width: 827px; display: flex; justify-content: flex-end;">
        {{form.releaseTime}}
      </el-col>
    </el-row>
    <FormTransfer :transferDialog="transferDialog" :transferDialogType="transferDialogType" :multiple="transferDialogMultiple" :transferCurrent="transferCurrent" @transferData="transferDataHandle" @closeTransfer="closeTransfer"/>
  </div>
</template>

<script>

import FormTransfer from "@/components/form/transfer.vue";

export default {
  name: "NoticeAuditType1",
  components: {FormTransfer},
  props: {
    params: {
      type: Object,
    },
    edit: {
      type: Boolean,
      default: false,
    }
  },
  data(){
    return{
      formDisplay: false,
      componentData: {},
      form:{},
      transferDialog: false,
      transferDialogType: '',
      transferDialogMultiple: false,
      transferCurrent: {},
    }
  },
  watch: {
    params: {
      handler(newVal) {
        this.form = newVal;
      },
      deep: true,
      immediate: true
    },
    edit:{
      handler(newVal){
        this.formDisplay =newVal;
      },
      deep: true,
      immediate: true
    }
  },
  methods:{
    showTransferDialog(transferDialogArr, transferDialogType, transferDialogMultiple, transferDialogQuery) {
      this.transferDialogArr = transferDialogArr; // 表单字段
      this.transferDialogType = transferDialogType; // 判断类型user:人员，unit:职位，department:部门,company:单位,plan:计划等
      this.transferDialogMultiple = transferDialogMultiple; // 是否多选
      if (transferDialogType === 'company') {
        this.transferCurrent.type = transferDialogQuery;
      }
      if (transferDialogType === 'user') {
        if(!transferDialogQuery) {
          this.$message({
            type: "warning",
            message: "请先选择单位!"
          });
          return
        }
        this.transferCurrent.deptId = transferDialogQuery;
      }
      //重组数组name和id
      this.transferCurrent.currentval = []
      if(this.form[transferDialogArr[0]]) {
        if (this.form[transferDialogArr[0]].indexOf(',') > -1) {
          this.form[transferDialogArr[0]].split(',').forEach((item, i) => {
            this.transferCurrent.currentval.push({name: this.form[transferDialogArr[1]].split(',')[i], id: item})
          })
        } else {
          this.transferCurrent.currentval = [{name: this.form[transferDialogArr[1]], id: this.form[transferDialogArr[0]]}]
        }
      }
      this.transferDialog = true;
    },
    closeTransfer() {
      this.transferDialog = false
      this.transferDialogType = ''
    },
    // 已选定数据的更新判断
    transferDataHandle(e) {
      this.transferDialog = false
      let currentval = [], currentLabel = []
      if (e.list.length > 0) {
        if (e.list.length > 1) {
          e.list.forEach(item => {
            currentval.push(item.id)
            currentLabel.push(item.name)
          })
        } else {
          currentval = [e.list[0].id]
          currentLabel = [e.list[0].name]
        }
        this.$set(this.form, this.transferDialogArr[0], currentval.join(','))
        this.$set(this.form, this.transferDialogArr[1], currentLabel.join(','))
      } else { // 如果返回的数据为空，也将当前页面数值清空
        this.$set(this.form, this.transferDialogArr[0], '')
        this.$set(this.form, this.transferDialogArr[1], '')
      }
      // console.log(this.form, 'this.form')
      this.transferDialogType = ''
    },
  },
}
</script>
